home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / pmdev / e / demos / demo.e < prev    next >
Encoding:
Text File  |  2000-02-28  |  9.2 KB  |  239 lines

  1. /* -- ----------------------------------------------------------------- -- *
  2.  * -- Program.....: Demo.e                                              -- *
  3.  * -- Author......: Daniel Kasmeroglu <raptor@cs.tu-berlin.de>          -- *
  4.  * -- Description.: Port of an example by Henrik Isaksson.              -- *
  5.  * -- ----------------------------------------------------------------- -- *
  6.  * -- Original header:                                                  -- *
  7.  * --                                                                   -- *
  8.  * --   $VER: Demo.c 2.1 (05.09.98)                                     -- *
  9.  * --                                                                   -- *
  10.  * --   Popup Menu example program                                      -- *
  11.  * --                                                                   -- *
  12.  * --   ©1996-1997 Henrik Isaksson                                      -- *
  13.  * --   All Rights Reserved.                                            -- *
  14.  * --                                                                   -- *
  15.  * --   Run and click the mouse in the window and over the dragbar!     -- *
  16.  * --   (two different menus)                                           -- *
  17.  * --                                                                   -- *
  18.  * -- ----------------------------------------------------------------- -- */
  19.  
  20. /* -- ----------------------------------------------------------------- -- *
  21.  * --                              Options                              -- *
  22.  * -- ----------------------------------------------------------------- -- */
  23.  
  24. OPT PREPROCESS       -> enable preprocessor
  25.  
  26.  
  27. /* -- ----------------------------------------------------------------- -- *
  28.  * --                              Modules                              -- *
  29.  * -- ----------------------------------------------------------------- -- */
  30.  
  31. MODULE 'libraries/popupmenu'  ,
  32.        'intuition/intuition'  ,
  33.        'utility/tagitem'      ,
  34.        'utility/hooks'        ,
  35.        'tools/inithook'       
  36.  
  37. MODULE 'popupmenu'
  38.  
  39.  
  40. /* -- ----------------------------------------------------------------- -- *
  41.  * --                               Main                                -- *
  42.  * -- ----------------------------------------------------------------- -- */
  43.  
  44. ->»» PROC main
  45. PROC main()
  46. DEF ma_window  : PTR TO window
  47. DEF ma_menu1   : PTR TO popupmenu
  48. DEF ma_menu2   : PTR TO popupmenu
  49. DEF ma_imsg1   : PTR TO intuimessage
  50. DEF ma_imsg2   : intuimessage
  51. DEF ma_handler : hook
  52. DEF ma_result
  53.  
  54.   ma_result := TRUE
  55.  
  56.   inithook( ma_handler, {hoo_MenuHandlerFunc}, {ma_result} )
  57.  
  58.   popupmenubase := OpenLibrary( 'popupmenu.library', 9 )
  59.   IF popupmenubase <> NIL
  60.  
  61.     ma_menu1 := PMMenu( 'Run Demos' ),
  62.                   PMItem( 'Disable' ),
  63.                     PMSimpleSub,
  64.                       PMInfo( 'This demo shows how to read the' ), PMEnd,
  65.                       PMInfo( 'state of a checkmark, and'       ), PMEnd,
  66.                       PMInfo( 'how to disable & enable an item' ), PMEnd,
  67.                       PMInfo( 'and its submenu.'                ), PMEnd,
  68.                       PMBar, PMEnd,
  69.                       PMItem( 'Run the demo !' ), PM_USERDATA, 'Disable', PMEnd,
  70.                     PMEnd,
  71.                   PMEnd,
  72.                   PMItem( 'PullDownMenu' ),
  73.                     PMSimpleSub,
  74.                       PMInfo( 'The PullDownMenu demo shows how'   ), PMEnd,
  75.                       PMInfo( 'you can use the popupmenu.library' ), PMEnd,
  76.                       PMInfo( 'for pulldown menus !'              ), PMEnd,
  77.                       PMBar, PMEnd,
  78.                       PMItem( 'Run the demo !' ), PM_USERDATA, 'PullDownMenu', PMEnd,
  79.                     PMEnd,
  80.                   PMEnd,
  81.                   PMItem( 'MenuVerify' ),
  82.                     PMSimpleSub,
  83.                       PMInfo(' This example uses the'      ), PMEnd,
  84.                       PMInfo( 'IDCMP_MENUVERIFY flag to'   ), PMEnd,
  85.                       PMInfo( 'combine standard intuition' ), PMEnd,
  86.                       PMInfo( 'menus with popupmenus int'  ), PMEnd,
  87.                       PMInfo( 'the same window !'          ), PMEnd,
  88.                       PMBar, PMEnd,
  89.                       PMItem( 'Run the demo !' ), PM_USERDATA, 'MenuVerify', PMEnd,
  90.                     PMEnd,
  91.                   PMEnd,
  92.                   PMItem( 'StartMenu' ),
  93.                     PMSimpleSub,
  94.                       PMInfo( 'This demo shows how to put'   ), PMEnd,
  95.                       PMInfo( 'images in you menus.'         ), PMEnd,
  96.                       PMInfo( 'You can find the menu at the' ), PMEnd,
  97.                       PMInfo( 'bottom of the screen.'        ), PMEnd,
  98.                       PMBar, PMEnd,
  99.                       PMItem( 'Run the demo !' ), PM_USERDATA, 'StartMenu', PMEnd,
  100.                     PMEnd,
  101.                   PMEnd,
  102.                   PMItem( 'Palette' ),
  103.                     PMSimpleSub,
  104.                       PMInfo( 'Popup menus can be used to' ), PMEnd,
  105.                       PMInfo( 'choose colours from too...' ), PMEnd,
  106.                       PMBar, PMEnd,
  107.                       PMItem( 'Colours' ),
  108.                         PMSimpleSub,
  109.                           PMCheckItem( 'Background' , 1 ), PM_COLOURBOX, 0, End,
  110.                           PMCheckItem( 'Shadow'     , 1 ), PM_COLOURBOX, 1, End,
  111.                           PMCheckItem( 'Shine'      , 1 ), PM_COLOURBOX, 2, End,
  112.                           PMCheckItem( 'Fill'       , 1 ), PM_COLOURBOX, 3, End,
  113.                           PMCheckItem( 'Halfshadow' , 1 ), PM_COLOURBOX, 4, End,
  114.                           PMCheckItem( 'Halfshine'  , 1 ), PM_COLOURBOX, 5, End,
  115.                           PMBar, PMEnd,
  116.                           PMItem( 'Use colour 1' ), PM_COLOURBOX, 9,  End,
  117.                           PMItem( 'Use colour 2' ), PM_COLOURBOX, 10, End,
  118.                           PMItem( 'Use colour 3' ), PM_COLOURBOX, 11, End,
  119.                         PMEnd,
  120.                       PMEnd,
  121.                     PMEnd,
  122.                   PMEnd,
  123.                 End
  124.  
  125.     ma_menu2 := PMMenu( 'PopupMenu Demo' ),
  126.                   PMItem( 'About...' ), PMEnd,
  127.                   PMBar, PMEnd,
  128.                   PMItem( 'Quit' ), PM_ID, 5, PMEnd,
  129.                 End
  130.  
  131.     IF (ma_menu1 <> NIL) AND (ma_menu2 <> NIL)
  132.  
  133.       -> Open a little window
  134.       ma_window := OpenWindowTagList( NIL,
  135.       [ WA_IDCMP       , IDCMP_CLOSEWINDOW OR IDCMP_MOUSEBUTTONS ,
  136.         WA_RMBTRAP     , TRUE              ,
  137.         WA_DRAGBAR     , TRUE              ,
  138.         WA_LEFT        , 150               ,
  139.         WA_TOP         , 100               ,
  140.         WA_WIDTH       , 150               ,
  141.         WA_HEIGHT      , 100               ,
  142.         WA_SIZEGADGET  , TRUE              ,
  143.         WA_DEPTHGADGET , TRUE              ,
  144.         WA_MINWIDTH    , 150               ,
  145.         WA_MAXWIDTH    , 1280              ,
  146.         WA_MINHEIGHT   , 100               ,
  147.         WA_MAXHEIGHT   , 1024              ,
  148.         WA_TITLE       , 'Popup Menu Demo' ,
  149.         WA_CLOSEGADGET , TRUE              ,
  150.         TAG_END ] )
  151.  
  152.       IF ma_window <> NIL
  153.  
  154.         WHILE ma_result <> FALSE
  155.  
  156.           -> Wait for a message
  157.           WaitPort( ma_window.userport )
  158.  
  159.           -> Get the message
  160.           WHILE (ma_imsg1 := GetMsg( ma_window.userport )) <> NIL
  161.  
  162.             CopyMem( ma_imsg1, ma_imsg2, SIZEOF intuimessage )
  163.             ReplyMsg( ma_imsg1 )
  164.  
  165.             IF ma_imsg2.class = IDCMP_CLOSEWINDOW
  166.               ma_result := FALSE
  167.             ELSEIF ma_imsg2.class = IDCMP_MOUSEBUTTONS
  168.  
  169.               IF (ma_imsg2.code = MENUDOWN) OR (ma_imsg2.code = MENUUP)
  170.  
  171.                 IF ma_window.mousey > ma_window.bordertop
  172.                   Pm_OpenPopupMenuA( ma_window,
  173.                   [ PM_MENU        , ma_menu1      ,
  174.                     PM_CODE        , ma_imsg2.code ,
  175.                     PM_MENUHANDLER , ma_handler    ,
  176.                     TAG_END ] )
  177.                 ELSE
  178.                   Pm_OpenPopupMenuA( ma_window,
  179.                   [ PM_MENU        , ma_menu2      ,
  180.                     PM_CODE        , ma_imsg2.code ,
  181.                     PM_MENUHANDLER , ma_handler    ,
  182.                     TAG_END ] )
  183.                 ENDIF
  184.  
  185.               ENDIF
  186.  
  187.             ENDIF
  188.  
  189.           ENDWHILE
  190.  
  191.         ENDWHILE
  192.  
  193.         CloseWindow( ma_window )
  194.  
  195.       ELSE
  196.         PrintF( 'Window error !\n' )
  197.       ENDIF
  198.  
  199.     ELSE
  200.       PrintF( 'Menu error !\n' )
  201.     ENDIF
  202.  
  203.     IF ma_menu1 <> NIL THEN Pm_FreePopupMenu( ma_menu1 )
  204.     IF ma_menu2 <> NIL THEN Pm_FreePopupMenu( ma_menu2 )
  205.  
  206.     CloseLibrary( popupmenubase )
  207.  
  208.   ELSE
  209.     PrintF( 'Cannot open "popupmenu.library" v9+ !\n' )
  210.   ENDIF
  211.  
  212. ENDPROC
  213. ->»»>
  214.  
  215.  
  216. /* -- ----------------------------------------------------------------- -- *
  217.  * --                          Hook-Functions                           -- *
  218.  * -- ----------------------------------------------------------------- -- */
  219.  
  220. ->»» HOOK hoo_MenuHandlerFunc
  221. PROC hoo_MenuHandlerFunc( men_hook : PTR TO hook, men_object, men_msg )
  222. DEF men_menu        : PTR TO popupmenu
  223. DEF men_bfr [ 128 ] : STRING
  224.  
  225.   men_menu := men_object
  226.   IF men_menu.ppm_UserData <> NIL
  227.  
  228.     StringF( men_bfr, 'RUN <>NIL: \s', men_menu.ppm_UserData )
  229.     IF FileLength( men_menu.ppm_UserData ) > 0 THEN Execute( men_bfr, NIL, NIL )
  230.  
  231.   ENDIF
  232.  
  233.   -> ID 5 means quit
  234.   IF men_menu.ppm_ID = 5 THEN PutLong( men_hook.data, FALSE )
  235.  
  236. ENDPROC
  237. ->»»>
  238.  
  239.